rm(list=ls())

library(foreign)
library(ggplot2)
library(gridExtra)
library(grid)
library(lattice)
library(tidyverse)
library(maps)
library(usmap)
library(mapproj)
library(dplyr)


############################## Diff Diff Graphs - Lagged DVs ############################## 
setwd("")

diffdiffall<-read.dta("covariate_balance_results_updated_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~outcome, nrow=1)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  scale_y_continuous(limits=c(-0.15, 0.15)) +
  labs(x="Model Specification", y="Effect of School Shooting on Lagged Outcomes", title="") +
  theme(text = element_text(size=18)) 

plot1 

ggsave(plot1, file="covariate_balance.pdf", width=5, height=3, scale=2)


############################## Diff Diff Graphs - Dem Vote Share ############################## 
setwd("")

diffdiffall<-read.dta("election_outcomes_results_updated_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~var, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Vote Share", title="") +
  theme(text = element_text(size=20)) 

plot1 

ggsave(plot1, file="elect_outcomes_redo_may_2020.pdf", width=6, height=4, scale=2)


############################## Diff Diff Graphs - Turnout ############################## 
setwd("")

diffdiffall<-read.dta("turnout_results_updated_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~var, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Voter Turnout", title="") +
  theme(text = element_text(size=20)) 

plot1 

ggsave(plot1, file="turnout_redo_may_2020.pdf", width=6, height=4, scale=2)

############################## Diff Diff Graphs - Local Elections ############################## 
setwd("")

diffdiffall<-read.dta("local_election_results_updated.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~treatment, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect on Local Gov't Dem. Share", title="") +
  theme(text = element_text(size=16)) +
  scale_x_continuous(breaks=c(1,2,3))

plot1 

ggsave(plot1, file="local_results_redo_may_2020.pdf", width=4, height=2.5, scale=2)

######################################################################
######################################################################
############################## APPENDIX ##############################
######################################################################
######################################################################

################################ Vote Share Close Controls ###########

setwd("")

diffdiffall<-read.dta("election_outcomes_results_closest_controls_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~treatment, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Vote Share", title="") +
  theme(text = element_text(size=20)) 

plot1 

ggsave(plot1, file="elect_outcomes_close_controls.pdf", width=6, height=4, scale=2)


################################ Turnout Close Controls ###########

setwd("")

diffdiffall<-read.dta("voter_turnout_results_closest_controls_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~treatment, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Vote Share", title="") +
  theme(text = element_text(size=20)) 

plot1 

ggsave(plot1, file="voter_turnout_close_controls.pdf", width=6, height=4, scale=2)

################################ Republican Unopposed ###########

setwd("")

diffdiffall<-read.dta("who_runs_republicans_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~treatment, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Republicans Running Unopposed", title="") +
  theme(text = element_text(size=20)) +
  scale_x_continuous(breaks=c(1,2,3))

plot1 

ggsave(plot1, file="republican_unopposed.pdf", width=6, height=4, scale=2)

################################ Democrat Unopposed ###########

setwd("")

diffdiffall<-read.dta("who_runs_democrats_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~treatment, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Democrats Running Unopposed", title="") +
  theme(text = element_text(size=20)) +
  scale_x_continuous(breaks=c(1,2,3))

plot1 

ggsave(plot1, file="democrat_unopposed.pdf", width=6, height=4, scale=2)

################################ Either Party Unopposed ###########

setwd("")

diffdiffall<-read.dta("who_runs_either_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~treatment, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Either Running Unopposed", title="") +
  theme(text = element_text(size=20)) +
  scale_x_continuous(breaks=c(1,2,3))

plot1 

ggsave(plot1, file="either_unopposed.pdf", width=6, height=4, scale=2)

############################## Timing ############################## 
setwd("")

diffdiffall<-read.dta("election_outcomes_results_dummy_treat.dta")
attach(diffdiffall) 

color.names<-c("black", "grey70")

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  aes(colour = factor(var)), position = pd) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr, colour = factor(var)), position = pd, width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr, colour = factor(var)), position = pd, width=0, size=2) +
  facet_wrap(~outcome, nrow=1)  +
  scale_colour_manual(values=color.names) + theme_bw() +theme(panel.grid.major = element_blank(), 
                                                              panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2,byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect on Voter Turnout/Vote Share", title="") +
  theme(text = element_text(size=25)) + 
  scale_y_continuous(limits=c(-0.2, 0.2)) 

plot1 

ggsave(plot1, file="elect_outcomes_dummy_treatment_results.pdf", width=6, height=4, scale=2)

################################ Longer Time Series ###########

setwd("")

diffdiffall<-read.dta("election_results_longer_time_series.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=11,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~treatment, nrow=1)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Vote Share", title="") +
  theme(text = element_text(size=20))  + scale_y_continuous(limits=c(-0.15, 0.15)) 


plot1 

ggsave(plot1, file="dem_vote_share_longer_time_series.pdf", width=7, height=4, scale=2)



################################ Quantile Regression ###########

setwd("")

diffdiffall<-read.dta("qunatile_regression_results.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=quantile)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=11,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Quantile", y="Difference-in-Differences Effect", title="") +
  theme(text = element_text(size=20))  + scale_y_continuous(limits=c(-1, 1)) +
  scale_x_continuous(breaks=c(0.1,0.2,0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9))

plot1 

ggsave(plot1, file="quantile_regression_results.pdf", width=7, height=4, scale=2)


############################## Diff Diff Graphs - Dem Vote Share ############################## 
setwd("")

diffdiffall<-read.dta("election_outcomes_results_updated_standarized_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~var, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Vote Share (Std.)", title="") +
  theme(text = element_text(size=20)) + scale_y_continuous(limits=c(-0.4, 0.4))

plot1 

ggsave(plot1, file="elect_outcomes_redo_may_2020_standardized.pdf", width=6, height=4, scale=2)


############################## Diff Diff Graphs - Turnout ############################## 
setwd("")

diffdiffall<-read.dta("turnout_results_updated_standardized_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_hline(aes(yintercept=0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_hline(aes(yintercept=-0.36), colour="black", linetype="dashed", size=2, alpha=0.2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~var, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Voter Turnout (Std.)", title="") +
  theme(text = element_text(size=20)) 

plot1 

ggsave(plot1, file="turnout_redo_may_2020_standardized.pdf", width=6, height=4, scale=2)



############################## Diff Diff Graphs - Dem Vote Share (Odd Year Treatment Included) ############################## 
setwd("")

diffdiffall<-read.dta("election_outcomes_updated_odd_years_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~var, nrow=1)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Vote Share", title="") +
  theme(text = element_text(size=17))

plot1 

ggsave(plot1, file="elect_outcomes_redo_may_2020_odd_years.pdf", width=7, height=3, scale=2)


############################## Diff Diff Graphs - Turnout  (Odd Year Treatment Included) ############################## 
setwd("")

diffdiffall<-read.dta("turnout_results_updated_odd_years_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~var, nrow=1)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of School Shooting on Voter Turnout", title="") +
  theme(text = element_text(size=17)) 

plot1 

ggsave(plot1, file="turnout_redo_may_2020_odd_years.pdf", width=7, height=3, scale=2)



############################## Diff Diff Graphs - Dem Vote  (Governors) ############################## 
setwd("")

diffdiffall<-read.dta("election_outcomes_results_updated_governors_final.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

color.names<-c("black", "grey70")

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=11,  aes(colour = factor(year)), position=pd) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr, colour = factor(year)),  position=pd, width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr, colour = factor(year)), position=pd, width=0, size=2) +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="bottom") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect on Democratic Vote Share of Governors", title="") +
  theme(text = element_text(size=16)) +
  scale_colour_manual(values=color.names) + scale_y_continuous(limits=c(-0.15, 0.15))

plot1 

ggsave(plot1, file="vote_share_redo_may_2020_governors.pdf", width=5, height=3, scale=2)

############################## Diff Diff Graphs - Dem Vote  (Governors--different treatments) ############################## 

setwd("")

diffdiffall<-read.dta("election_outcomes_results_updated_governors_cleaned.dta")
attach(diffdiffall) 

pd <- position_dodge(width=0.3)  

plot1<-ggplot(diffdiffall, aes(y=coef,  x=model_num)) + 
  geom_hline(aes(yintercept=0), colour="#990000", linetype="dashed", size=2) +
  geom_point(data=diffdiffall, size=8,  colour = "black") +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.96*stderr, ymax= coef+1.96*stderr),  colour = "black", width=0, size=1) +
  geom_errorbar(data=diffdiffall, aes(ymin=coef-1.64*stderr, ymax= coef+1.64*stderr),  colour = "black", width=0, size=2) +
  facet_wrap(~var, nrow=2)  +
  theme_bw() +theme(panel.grid.major = element_blank(), 
                    panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
  theme(legend.position="none") +
  guides(fill=guide_legend(nrow=2, byrow=TRUE))+
  theme(legend.title = element_blank()) +
  labs(x="Model Specification", y="Effect of Democratic Vote Share of Governors", title="") +
  theme(text = element_text(size=20)) + scale_y_continuous(limits=c(-0.25, 0.25))

plot1 

ggsave(plot1, file="vote_share_redo_may_2020_governors_different_treatments.pdf", width=6, height=4, scale=2)



################################ Shootings Mapped -- Figure 1 ###########

us_states <- map_data("state")

state_full<-read.dta("/Users/johnholbein/Dropbox (Batten School @ UVA)/Work/School Shootings/Data/School Shooting Locations/Shooting Location Extended with County for Map.dta")

p <- ggplot(data = us_states,
            mapping = aes(x = long, y = lat, group = group)) 

p1 <- p + geom_polygon(colour = "white", fill="grey80", size = 0.05) +  
  coord_map(projection = "albers", lat0 = 39, lat1 = 45) + 
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
        panel.background = element_blank(), axis.line = element_line(colour = "grey40")) + theme_void()  +
  guides(fill=guide_legend(title=""))  +
  theme(text = element_text(size=18)) 

p2 <- p1 +  geom_point(data=state_full, aes(x = g_lon, y = g_lat, group="none",  
                                            size=(deaths_and_injuries),  
                                            colour=(year)), alpha=0.7) +   scale_size(range = c(3, 15)) 

p3 <- p2 + theme(legend.position="right") + labs(colour='Year')  + labs(size='Deaths and Injuries') 

p3

ggsave(p3, file="shootings_dot_map.pdf", width=10, height=5, scale=2, dpi=300)






